﻿using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace DiskUsage.CoreLib
{
    [DebuggerDisplay("{Name} - {PathType} - Size {Size}")]
    public class DirectoryEntry
    {
        private DirectoryEntry()
        {
            Errors = new Dictionary<Exception, string>();
            Children = new List<DirectoryEntry>();
        }

        public DirectoryEntry(string path)
            : this()
        {
            if (string.IsNullOrEmpty(path))
                throw new InvalidPathException("Path cannot be empty!");
            var type = PathUtils.GetPathType(path);
            if (type == PathType.Invalid)
                throw new InvalidPathException(path);

            Path = path;
            Type = type;
        }

        public string Name { get { return System.IO.Path.GetFileName(Path); } }
        public bool HasErrors { get { return Errors.Count > 0; } }
        public string Path { get; private set; }
        public PathType Type { get; private set; }
        public Dictionary<Exception, string> Errors { get; private set; }
        public long Size { get; set; }
        public List<DirectoryEntry> Children { get; private set; }
    }
}
